package com.example.zzy.zzytest.algo.sort.n2sort;

import static com.example.zzy.zzytest.test.LeeTest.exch;

public class BubbleSort {
    private static void sort(int[] arr) {

        for (int i = 1; i < arr.length; i++) {
            //flag 假设该次没有进行交换
            boolean flag = false;
            for (int j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    exch(arr, j, j + 1);
                    flag = true;
                }
            }

            if (!flag) {
                break;
            }
        }

    }

    public static void main(String[] args) {
        int[] nums = new int[]{3, 1, 5, 0, 6, 2};
        sort(nums);
    }
}
